/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SetupPayloadBox.java
 *
 * Created on Jul 30, 2009, 2:07:18 AM
 */

package Falcon;

import org.jdesktop.application.Action;

/**
 *
 * @author Joe
 */
public class SetupRecovery extends javax.swing.JDialog {

    /** Creates new form TestStrBox */
    public SetupRecovery(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        settingsHandler = SettingsHandler.getInstance();
        settingsHandler.loadSettings();
        setDefaults();
        fillValues();
    }


    private void setDefaults(){
        callsignVal = settingsHandler.get("RecoverySetup_callsignVal");
    }
    private void fillValues(){
        callsignText.setText(callsignVal);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        cancelButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        okButton = new javax.swing.JButton();
        callsignLabel = new javax.swing.JLabel();
        callsignText = new javax.swing.JTextField();
        jSeparator4 = new javax.swing.JSeparator();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(Falcon.FalconMainApp.class).getContext().getResourceMap(SetupRecovery.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N
        setResizable(false);

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(Falcon.FalconMainApp.class).getContext().getActionMap(SetupRecovery.class, this);
        cancelButton.setAction(actionMap.get("cancelButton")); // NOI18N
        cancelButton.setText(resourceMap.getString("cancelButton.text")); // NOI18N
        cancelButton.setName("cancelButton"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jSeparator1.setName("jSeparator1"); // NOI18N

        okButton.setAction(actionMap.get("okButton")); // NOI18N
        okButton.setText(resourceMap.getString("okButton.text")); // NOI18N
        okButton.setName("okButton"); // NOI18N

        callsignLabel.setText(resourceMap.getString("callsignLabel.text")); // NOI18N
        callsignLabel.setName("callsignLabel"); // NOI18N

        callsignText.setName("callsignText"); // NOI18N

        jSeparator4.setName("jSeparator4"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE)
                    .addComponent(jLabel1)
                    .addComponent(callsignLabel)
                    .addComponent(callsignText, javax.swing.GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE)
                    .addComponent(jSeparator4, javax.swing.GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(okButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cancelButton)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(callsignLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(callsignText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cancelButton)
                    .addComponent(okButton))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    @Action
    public void okButton() {
        callsignVal = callsignText.getText();
        FalconMainView.getInstance().updateCallsign(callsignVal);
        settingsHandler.put("RecoverySetup_callsignVal", callsignText.getText());
        settingsHandler.saveSettings();
        this.setVisible(false);
    }

    @Action
    public void cancelButton() {
        callsignText.setText(callsignVal);
        this.setVisible(false);
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel callsignLabel;
    private javax.swing.JTextField callsignText;
    private javax.swing.JButton cancelButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JButton okButton;
    // End of variables declaration//GEN-END:variables


    private String callsignVal;
    private SettingsHandler settingsHandler;

    public String getCallsignVal(){
        return callsignVal;
    }

}
